<template>
  <div class="app-container">
    <h4 class="form-header h4">厂家管理</h4>
    <el-form
      :model="queryParamsAAAAA"
      ref="queryFormAAAAA"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="菜单名称" prop="name">
        <el-input
          v-model="queryParamsAAAAA.name"
          placeholder="请输入名称"
          clearable
          @keyup.enter.native="handleQueryAAAAA"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQueryAAAAA"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQueryAAAAA"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-form ref="form" :model="formAAAAA" label-width="80px">
      <el-row style="display: flex; margin-bottom: 20px">
        <el-col>
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAddAAAAA()"
            >新增</el-button
          >
        </el-col>
      </el-row>
    </el-form>

    <el-table v-loading="loadingAAAAA" :data="listAAAAA" height="580">
      <el-table-column label="id" prop="id" width="60" />
      <el-table-column
        label="厂家名称"
        prop="name"
        :show-overflow-tooltip="true"
        width="150"
      />
      <el-table-column
        label="api"
        prop="apiUrl"
        :show-overflow-tooltip="true"
        width="250"
      />
      <el-table-column
        label="tokenUrl"
        prop="tokenUrl"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="tokenJson"
        prop="tokenJson"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="180"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdateAAAAA(scope.row)"
            v-hasPermi="['interface_center:manufacturer:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDeleteABCDE(scope.row)"
            v-hasPermi="['interface_center:manufacturer:remove']"
            >删除</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleTestConnectAAAAA(scope.row)"
            v-hasPermi="['interface_center:manufacturer:connect']"
            >测试</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="totalAAAAA > 0"
      :total="totalAAAAA"
      :page.sync="queryParamsAAAAA.pageNum"
      :limit.sync="queryParamsAAAAA.pageSize"
      @pagination="getListAAAAA"
      style="display: flex; justify-content: center"
    />

    <!-- 添加或修改用户配置对话框 -->
    <el-dialog
      :visible.sync="openAAAAA"
      width="800px"
      :before-close="cancelAAAAA"
    >
      <el-form
        label-position="left"
        ref="formUpdateAAAAA"
        :model="formAAAAA"
        @submit.native.prevent
        label-width="80px"
        :rules="rulesAAAAA"
      >
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="厂家名称" prop="name">
              <el-input
                v-model="formAAAAA.name"
                placeholder="请输入厂家名称"
                clearable
                :style="{ width: '100%' }"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="请求头" prop="headers">
              <el-input
                v-model="formAAAAA.headers"
                type="textarea"
                placeholder="请输入请求头"
                :autosize="{ minRows: 4, maxRows: 4 }"
                :style="{ width: '100%' }"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="apiUrl" prop="apiUrl">
              <el-input
                v-model="formAAAAA.apiUrl"
                type="textarea"
                placeholder="请输入apiUrl"
                :autosize="{ minRows: 4, maxRows: 4 }"
                :style="{ width: '100%' }"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="tokenUrl" prop="tokenUrl">
              <el-input
                v-model="formAAAAA.tokenUrl"
                type="textarea"
                placeholder="请输入tokenUrl"
                :autosize="{ minRows: 4, maxRows: 4 }"
                :style="{ width: '100%' }"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="tokenJson" prop="tokenJson">
              <el-input
                v-model="formAAAAA.tokenJson"
                type="textarea"
                placeholder="请输入tokenJson"
                :autosize="{ minRows: 4, maxRows: 4 }"
                :style="{ width: '100%' }"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormAAAAA">确 定</el-button>
        <el-button @click="cancelAAAAA">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import request from "@/utils/request";
import {
  JSONreflush,
  emptyIsTrue,
  emptyIsFalse,
  removeBracketsAndPipes,
} from "@/api/123wwwww/universalMethod.js";

export default {
  name: "manufacturer",
  dicts: ["sys_show_hide", "sys_normal_disable"],
  data() {
    return {
      loadingAAAAA: true,
      showSearch: true,
      listAAAAA: [],
      totalAAAAA: 0,
      title: "",
      openAAAAA: false,
      // 查询参数
      queryParamsAAAAA: {
        name: undefined,
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      formAAAAA: {},
      // 表单校验
      rulesAAAAA: {
        name: [
          {
            required: true,
            message: "请输入厂家名称",
            trigger: "blur",
          },
        ],
        headers: [
          {
            required: true,
            message: "请输入请求头",
            trigger: "blur",
          },
        ],
        apiUrl: [
          {
            required: true,
            message: "请输入apiUrl",
            trigger: "blur",
          },
        ],
        tokenUrl: [
          {
            required: true,
            message: "请输入tokenUrl",
            trigger: "blur",
          },
        ],
        tokenJson: [
          {
            required: true,
            message: "请输入tokenJson",
            trigger: "blur",
          },
        ],
      },
    };
  },
  created() {
    this.toSTART();
  },
  methods: {
    toSTART() {
      this.getListAAAAA();
    },
    //---------------------表的方法---------------------
    /** 搜索按钮操作 */
    handleQueryAAAAA() {
      this.getListAAAAA();
    },
    /** 重置按钮操作 */
    resetQueryAAAAA() {
      this.resetForm("queryFormAAAAA");
      this.handleQueryAAAAA();
    },
    // 获取页面的表格所有数据
    getListAAAAA() {
      this.loadingAAAAA = true;
      request({
        url: "/ruoyi-managerapi/manufacturer/list",
        method: "get",
        params: this.queryParamsAAAAA,
      }).then((response) => {
        this.listAAAAA = response.rows;
        this.totalAAAAA = response.total;
        this.loadingAAAAA = false;
      });
    },
    //取消按钮
    cancelAAAAA() {
      this.$confirm("是否关闭弹出框?", "提示", {
        cancelButtonText: "取消",
        confirmButtonText: "确定",
        type: "warning",
        center: true,
      })
        .then(() => {
          this.openAAAAA = false;
          this.formAAAAA = {};
          this.resetForm("formAAAAA");
        })
        .catch(() => {});
    },
    handleAddAAAAA() {
      this.formAAAAA = {
        //表的id
        id: 0,
      };
      this.openAAAAA = true;
    },
    handleUpdateAAAAA(row) {
      this.formAAAAA = {};
      this.openAAAAA = true;
      //重要   需要传值而不是本体
      this.formAAAAA = JSONreflush(row);
    },

    /** 提交按钮 */
    submitFormAAAAA() {
      this.$refs.formUpdateAAAAA.validate((valid) => {
        if (!valid) {
          this.$message("内容不符合规则");
          return false;
        }
        let update = this.getUpdateObjectAAAAA(this.formAAAAA);
        let method = "";
        //判断id为0就新增，id不为0就修改
        if (update.id == 0) {
          method = "post";
        } else {
          method = "put";
        }
        request({
          url: "/ruoyi-managerapi/manufacturer",
          method: method,
          data: update,
        }).then((response) => {
          console.log(response);
          this.$modal.msgSuccess("修改成功");
          this.openAAAAA = false;
          this.toSTART();
        });
      });
    },

    /** 更新对象修改 */
    getUpdateObjectAAAAA(ObjectABCDE) {
      //只传值不修改原数值
      let updateObjectABCDE = JSONreflush(ObjectABCDE);
      //删除空字段
      for (let key in updateObjectABCDE) {
        if (emptyIsTrue(updateObjectABCDE[key])) {
          this.$delete(updateObjectABCDE, key);
        }
      }
      //删除多余字段
      //this.$delete(updateObjectABCDE, "index");

      return updateObjectABCDE;
    },

    handleTestConnectAAAAA(entity) {
      request({
        url: "/ruoyi-managerapi/manufacturer/connect" + entity.id * 1,
        method: "get",
      }).then((response) => {
        console.log(response);
        this.$modal.msgSuccess("测试成功");
        this.toSTART();
      });
    },

    handleDeleteABCDE(row) {
      this.$confirm("此操作将进行删除命令, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          this.deleteABCDE(row);
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    deleteABCDE(entity) {
      request({
        url: "/ruoyi-managerapi/manufacturer/" + entity.id * 1,
        method: "delete",
      }).then(() => {
        this.$modal.msgSuccess("删除成功");
        this.toSTART();
      });
    },
  },
};
</script>
